home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / MEMORY.SWG / 0002_Re: 32bit Move() and Fillchar() replacem.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  3.0 KB  |  116 lines

  1. {
  2. > >If anyone wants to see my "improved" move() and fillchar() which I put
  3. > >into a unit which I almost always link in I'd be happy to post it.  (I
  4. > >know that TCA has an even better one though, in case he'd like to post
  5. > >his version as well)
  6. >
  7. > Oh, fine.  Now that the world knows, I suppose I have to post it ;)
  8. >
  9. Thank you for so graciously accepting the terms before anyone wanted me
  10. to post my much more elementary 16-bit version as below:
  11. }
  12. procedure move (var src, dest; count : word); assembler;
  13.  
  14. asm
  15.   push ds
  16.     mov bx, count
  17.     mov cx, bx
  18.     shr cx, 1
  19.  
  20.     les di, src
  21.     lds si, dest
  22.     rep movsw
  23.  
  24.     and bx, 1
  25.     jz @NoMovsB
  26.     movsb
  27.    @NoMovsB: 
  28.  
  29.   pop ds
  30. end;
  31.  
  32. > This is a 32bit move() replacement.  Just throw the procedure in at the 
  33. > top of your program, and all your move() calls will work a little faster
  34. > (about 4 times faster for counts above 128 bytes).
  35. > procedure move(var Source,Dest; Count:word); assembler;
  36. > asm
  37. >     push    ds
  38. >     les    di,Dest
  39. >     lds    si,Source
  40. >     mov    cx,count
  41. >     mov    bx,cx
  42. >     shr    cx,2
  43. >     db 66h;    rep movsw
  44. >     and    bx,3
  45. >     mov    cx,bx
  46. >     rep    movsb
  47. >     pop    ds
  48. > end;
  49. >
  50. I remember yours looking a little different then that, maybe I'm thinking 
  51. of fillchar (later on)... but not to be picky, since dx isn't used, 
  52. couldn't you use mov dx, ds and mov ds, dx instead of push and pop 
  53. respectively?
  54.  
  55. > The fillchar() replacement isn't as nice, since with fillchar you can do 
  56. > things like: fillchar(foo,128,'H'); or fillchar(foo,128,TRUE);  
  57. > That makes conversions more difficult.  Still, for those of you who don't 
  58. > do that:
  59. > procedure fillchar(var X; Count:word; Value:byte); assembler;
  60. > asm
  61. >     les    di,X
  62. >     mov    cx,count
  63. >     mov    al,value
  64. >     mov    ah,al
  65. >     mov    bx,ax
  66. >     db 66h;    shl ax,16
  67. >     mov    ax,bx
  68. >     mov    bx,cx
  69. >     shr    cx,2
  70. >     db 66h; rep stosw
  71. >     and    bx,3
  72. >     mov    cx,bx
  73. >     rep    stosb
  74. > end;
  75. Hmmm... you must have rewritten both of them since I last saw them, as I 
  76. remember something utilizing adc in one of those... oh well, thse look 
  77. more logical anyway :)
  78.  
  79. > To get around the character or boolean types, do ord('H') or ord(TRUE).
  80. > (It all compiles to the same code).
  81. > This procedure will only increase the speed of fillchar() calls when the 
  82. > Count is above 128 or so.  It will also fillchar to pointers faster than 
  83. > arrays (since pointers are aligned, and arrays are [usually] not).  I 
  84. > just wrote the fillchar() procedure, so it is not as optimized as it
  85. > could be.
  86. How about I put up my fillchar as well, just for comparison's sake (it's, 
  87. once again, only 16-bit, but it seems to work just fine anyway :)
  88.  
  89. procedure FillChar (var src, dest; count : word; value : byte); assembler;
  90.  
  91. asm
  92.   mov bx, count
  93.   mov cx, bx
  94.   shr cx, 1
  95.  
  96.   mov al, value
  97.   mov ah, al
  98.  
  99.   les di, dest
  100.   rep stosw
  101.  
  102.   and bx, 1
  103.   jz @NoStosB
  104.   stosb
  105.  @NoStosB:
  106. end;
  107.  
  108. In other words it's my move() only with ax = 257*value and, well, a fill
  109. instead of a move. :)
  110.  
  111.